package com.gt.self.controller;

import com.gt.common.AjaxResult;
import com.gt.self.domain.vo.PrintInfoVo;
import com.gt.self.domain.vo.ReportInfoVo;
import com.gt.self.domain.vo.ReportParamVo;
import com.gt.self.service.SelfMachinePrintService;
import com.gt.self.service.SelfMachineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.PrintStream;
import java.text.ParseException;
import java.util.List;

@Slf4j
@Api(tags = "自助打印功能")
@RestController
@RequestMapping("self/print")
//@CrossOrigin
public class SelfMachinePrintController {

    @Autowired
    private SelfMachinePrintService selfMachinePrintService;

    @ApiOperation("自助打印接口")
    @GetMapping("selfServicePrint")
    public AjaxResult selfServicePrint(String commonNo) throws ParseException {
        AjaxResult printResult = selfMachinePrintService.selfServicePrint(commonNo);
        return printResult;
    }

    @ApiOperation("开始打印报告")
    @GetMapping("print")
    public AjaxResult print(List<String> applyNos)  {
        AjaxResult printResult = selfMachinePrintService.print(applyNos);
        return printResult;
    }

    @ApiOperation("查询已打印报告信息")
    @PostMapping("selectFinishPrintInfo")
    public AjaxResult selectFinishPrintInfo(@RequestBody ReportParamVo reportParamVo) {

        if (StringUtils.isNotBlank(reportParamVo.getPatientId()) || StringUtils.isNoneBlank(reportParamVo.getIdCardNo())) {
            List<PrintInfoVo> printInfoVoList = selfMachinePrintService.selectFinishPrintInfo(reportParamVo);
            return AjaxResult.success(printInfoVoList);
        }

        if (StringUtils.isNotBlank(reportParamVo.getApplyBillNo())) {
            List<PrintInfoVo> printInfoVoList = selfMachinePrintService.selectFinishPrintInfoByApplyNo(reportParamVo);
            return AjaxResult.success(printInfoVoList);
        }

        log.error("查询已打印报告信息接口-请求参数不符合！");
        return AjaxResult.error("请求参数不符合");
    }

    /**
     * 如果打印调用这个接口，就把后面的1去掉，把上面没有1的注释，前端不用改
     *
     * @param reportParamVo
     * @return
     * @throws ParseException
     */
    @ApiOperation("自助打印接口（打印同步PDF）")
    @PostMapping("selfServicePrint1")
    public AjaxResult selfServicePrint1(@RequestBody ReportParamVo reportParamVo) throws ParseException {

        AjaxResult printResult = selfMachinePrintService.selfServicePrint1(reportParamVo);

        return printResult;
    }

}


